home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / events / event32.c < prev    next >
Text File  |  1993-12-06  |  4KB  |  127 lines

  1. /**
  2.  ** EVENT32.C
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #ifndef __GNUC__
  25. #error  This file is only for the DJGPP 32-bit version!!!!
  26. #endif
  27.  
  28. #include <stdlib.h>
  29. #include "eventque.h"
  30.  
  31. asm(                                       "\n\
  32.     .data                                \n\
  33.     .align  4                            \n\
  34. _mousedraw_painter:        /* pointer to the function */        \n\
  35.     .long    0        /* to draw mouse */            \n\
  36. _mousedraw_active_p:        /* pointer to flag to zero */        \n\
  37.     .long    0        /* when drawing is done */        \n\
  38. _mousedraw_contaddr_p:        /* pointer to dword containing */    \n\
  39.     .long    0        /* return address from mouse draw */    \n\
  40.     .text                                \n\
  41.     .align  2,144                            \n\
  42. _mousedraw_func:                            \n\
  43.     cli                                \n\
  44.     pushl    %eax        /* place for return address */        \n\
  45.     pushf                                \n\
  46.     pushl    %eax        /* save EAX */                \n\
  47.     movl    _mousedraw_contaddr_p,%eax                \n\
  48.     movl    (%eax),%eax    /* fix up return address */        \n\
  49.     movl    %eax,8(%esp)                        \n\
  50.     pushl    %ebx                            \n\
  51.     pushl    %ecx                            \n\
  52.     pushl    %edx                            \n\
  53.     pushl    %esi                            \n\
  54.     pushl    %edi                            \n\
  55.     movl    _mousedraw_painter,%eax                    \n\
  56.     sti                                \n\
  57.     call    *%eax                            \n\
  58.     cli                                \n\
  59.     popl    %edi                            \n\
  60.     popl    %esi                            \n\
  61.     popl    %edx                            \n\
  62.     popl    %ecx                            \n\
  63.     popl    %ebx                            \n\
  64.     movl    _mousedraw_active_p,%eax                \n\
  65.     movb    $0,(%eax)    /* clear active flag */            \n\
  66.     popl    %eax                            \n\
  67.     popf                                \n\
  68.     sti                                \n\
  69.     ret            /* back to program */              "
  70. );
  71.  
  72. static int  have_queue = 0;
  73.  
  74. /*
  75.  * These are actually local symbols at the link level, we just have to
  76.  * trick the C compiler
  77.  */
  78. extern void mousedraw_func(void);
  79. extern void (*mousedraw_painter)(void);
  80. extern char *mousedraw_active_p;
  81. extern long *mousedraw_contaddr_p;
  82.  
  83.  
  84. void EventQueueDeInit(void)
  85. {
  86.     if(have_queue) {
  87.         asm volatile(                           "\n\
  88.         movl   $0x00ff,%%eax                    \n\
  89.         xorl   %%ebx,%%ebx                    \n\
  90.         int    $0x33                          "
  91.         : /* nothing */
  92.         : /* nothing */
  93.         : "ax", "bx", "cx", "dx"
  94.         );
  95.         have_queue = 0;
  96.     }
  97. }
  98.  
  99. EventQueue *EventQueueInit(int qsize,int ms_stksize,void (*msdraw)(void))
  100. {
  101.     EventQueue *queue;
  102.     int ack;
  103.  
  104.     if(qsize < 20) qsize = 20;
  105.     if(msdraw != NULL) {
  106.         mousedraw_painter = msdraw;
  107.         msdraw = mousedraw_func;
  108.     }
  109.     asm volatile(                               "\n\
  110.         movl   $0x00ff,%%eax                    \n\
  111.         movl   %2,%%ebx                        \n\
  112.         movl   %3,%%ecx                        \n\
  113.         int       $0x33                        \n\
  114.         movl   %%eax,%0                        \n\
  115.         movl   %%ebx,%1                        \n\
  116.         movl   %%ecx,_mousedraw_contaddr_p                \n\
  117.         movl   %%edx,_mousedraw_active_p                  "
  118.         : "=g" (ack),   "=g" (queue)
  119.         : "g"  (qsize), "g"  (msdraw)
  120.         : "ax", "bx", "cx", "dx"
  121.     );
  122.     if(ack != 0x0ff0) queue = NULL;
  123.     have_queue = (queue != NULL) ? 1 : 0;
  124.     return(queue);
  125. }
  126.  
  127.